package com.mzy.linear_struct.hot100.二分查找;

/**
 * @Author: mizy3
 * @Date: 2024/09/06/下午3:05
 * @Description:
 */
public class Pro35搜索插入位置 {

    public int searchInsert(int[] nums, int target) {
        int l = 0;
        int r = nums.length - 1;
        int mid = 0;
        while (l <= r) {
            mid = (r - l) + r >> 1;
            if (nums[mid] < target) {
                l = mid + 1;
            } else if (nums[mid] > target) {
                r = mid - 1;
            }else {
                return mid;
            }
        }

        return mid + 1;
    }
}























